package com.heima.admin.controller.v1;

import com.heima.admin.aspect.SysLog;
import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    AdChannelService adChannelService;

    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }


    @PostMapping("/save")
    @Override
    @SysLog("保存频道信息")
    public ResponseResult save(@RequestBody AdChannel adchannel) {
        log.info("method is save,parms is {}",adchannel);
        System.out.println("保存方法执行了");
        return adChannelService.insert(adchannel);
    }

    @PostMapping("/update")
    @Override
    @SysLog("修改频道信息")
    public ResponseResult update(@RequestBody AdChannel adchannel) {
        System.out.println("修改方法执行了");
        return adChannelService.update(adchannel);
    }

    @GetMapping("/del/{id}")
    @Override
    @SysLog("删除频道信息")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        System.out.println("删除方法执行了");
        return adChannelService.deleteById(id);
    }

    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
